<?php

namespace app\controller\api;


use app\service\VirtualDeviceService;
use app\validate\VirtualDeviceValidate;
use share\controller\ApiBaseController;
use share\service\ContextService;

class VirtualDeviceController extends ApiBaseController{

    protected $beforeActionList = [
        "checkSign",
        "checkUser", 
    ];

    /**
     * @description: 
     * @return {*}
     * @use: 
     */
    public function initValidate(){
        $this->validate = new VirtualDeviceValidate();
    }

    /**
     * 列表详情
     */
    public function list_action(){    
        $params = [];
        $userInfo = ContextService::getUserInfo();
        $params['uid'] = $userInfo['id'];
        $res = VirtualDeviceService::getAllByUser($params);
        return self::ok($res);
    }

     /**
     * 设置
     */
    public function set_action(){
        $input = $this->check();     
        $userInfo = ContextService::getUserInfo();
        $input['uid'] = $userInfo['id'];  
        $res = VirtualDeviceService::setDeviceInfo($input);      
        return self::ok($res);
    }
 
    /**
     * 删除分享规则
     */
    public function del_action(){
        $input = $this->check();
        $userInfo = ContextService::getUserInfo();
        $input['uid'] = $userInfo['id'];  
        $res = VirtualDeviceService::delDevice($input);          
        return self::ok($res);
    }

    /**
     * 删除子设备规则
     */
    public function del_sub_action(){
        $input = $this->check();
        $userInfo = ContextService::getUserInfo();
        $input['uid'] = $userInfo['id'];  
        $res = VirtualDeviceService::delSubDevice($input['uid'],$input['shareId'],$input['mainId'],$input['subIds']);    
        return self::ok($res);
    }
   
}